package it.ap.sa.core.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DatabaseUtil {

	private static CoreProperties property = SpringContextProvider.getApplicationContext().getBean(CoreProperties.class);
	
	/**
	 * Restituisce la connessione al DB
	 * 
	 * @return {@link Connection} - DB connection
	 * @throws SQLException
	 * @throws ClassNotFoundException
	 */
	public static Connection getConnection() throws SQLException, ClassNotFoundException {
		Class.forName(property.jdbcDriver);
		Properties props = new Properties();
		props.setProperty("user", property.jdbcUsername);
		props.setProperty("password", property.jdbcPassword);
		return DriverManager.getConnection(property.jdbcUrl, props);
	}

}
